#include "QQCentralStackedWidget.h"

QQCentralStackedWidget::QQCentralStackedWidget(QWidget* parent)
	: QStackedWidget(parent)
{
	this->setObjectName("QQCentralStackedWidget");
	mThemeMode = eTheme->getThemeMode();
	mIsTransparent = false;
	mIsHasRadius = true;
	connect(eTheme, &ElaTheme::themeModeChanged, this, &QQCentralStackedWidget::onThemeModeChanged);
}

QQCentralStackedWidget::~QQCentralStackedWidget()
{
}

void QQCentralStackedWidget::onThemeModeChanged(ElaThemeType::ThemeMode themeMode)
{
	mThemeMode = themeMode;
}

void QQCentralStackedWidget::setIsTransparent(bool isTransparent)
{
	this->mIsTransparent = isTransparent;
	update();
}

bool QQCentralStackedWidget::getIsTransparent() const
{
	return mIsTransparent;
}

void QQCentralStackedWidget::setIsHasRadius(bool isHasRadius)
{
	this->mIsHasRadius = isHasRadius;
	update();
}

void QQCentralStackedWidget::paintEvent(QPaintEvent* event)
{
	if (!mIsTransparent)
	{
		QPainter painter(this);
		QRect targetRect = this->rect();
		targetRect.adjust(1, 1, 10, 10);
		painter.save();
		painter.setRenderHint(QPainter::Antialiasing);
		painter.setPen(QPen(ElaThemeColor(mThemeMode, BasicBaseLine), 1.5));
		painter.setBrush(ElaThemeColor(mThemeMode, WindowCentralStackBase));
		if (mIsHasRadius)
		{
			painter.drawRoundedRect(targetRect, 10, 10);
		}
		else
		{
			painter.drawRect(targetRect);
		}
		painter.restore();
	}
	QStackedWidget::paintEvent(event);
}
